package com.zhang.hadoop.netty.netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.Charset;

/**
 * @author zhang yufei
 * @date 2022/2/10 10:11 上午
 **/
public class NettyByteBuf02 {

    public static void main(String[] args) {
        ByteBuf byteBuf = Unpooled.copiedBuffer("hello,word!", Charset.forName("utf-8"));
        //使用相关的方法
        if(byteBuf.hasArray()){
            byte[] content=byteBuf.array();
            //将content转成字符串
            System.out.println(new String(content,Charset.forName("utf-8")));
            System.out.println("byteBuf="+byteBuf);
            System.out.println(byteBuf.arrayOffset());
            System.out.println(byteBuf.readerIndex());
            System.out.println(byteBuf.writerIndex());
        }
    }
}
